package com.elong.businesstravel.modules.member.adapter;

import java.util.List;

import com.elong.businesstravel.R;
import com.elong.businesstravel.entitys.AccountInfo;
import com.elong.businesstravel.entitys.RedPurse;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
/**
 * 我的红包
 * @author lenovo
 *
 */
public class RedPurseAdapter extends BaseAdapter {

	private Context mContext;
	private List<RedPurse> mRedPurses;
	
	public RedPurseAdapter(Context context, List<RedPurse> redPurses) {
		mContext = context;
		mRedPurses = redPurses;
	}

	@Override
	public int getCount() {
		return mRedPurses.size();
	}

	@Override
	public Object getItem(int arg0) {
		return mRedPurses.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		
		if(null == arg1){
			arg1 = LayoutInflater.from(mContext).inflate(R.layout.adapter_red_purse, null);
		}
		
		if (null == arg1) {
			arg1 = LayoutInflater.from(mContext).inflate(
					R.layout.adapter_red_purse, null);
		}
		
		RedPurse redPurse = mRedPurses.get(arg0);

		TextView bonusTextView = (TextView) arg1
				.findViewById(R.id.bonusTextView);
		bonusTextView.setText("+" + redPurse.addscore + "元");
		bonusTextView.setTextColor(mContext.getResources().getColor(
				R.color.money_red));

		ImageView stateImageView = (ImageView) arg1
				.findViewById(R.id.stateImageView);
		if (-1 == redPurse.status) {
			// 已过期
			stateImageView.setVisibility(View.VISIBLE);
			stateImageView.setImageResource(R.drawable.ic_red_purse_yiguoqi);
		} else if(0 == redPurse.status){
			//已使用
			stateImageView.setVisibility(View.VISIBLE);
			stateImageView.setImageResource(R.drawable.ic_red_purse_yishiyong);
		}else if (redPurse.status > 0) {
			//未使用
			stateImageView.setVisibility(View.VISIBLE);
			stateImageView.setImageResource(R.drawable.ic_red_purse_weishiyong);
		}

		TextView titleTextView = (TextView) arg1
				.findViewById(R.id.titleTextView);
			titleTextView.setText(redPurse.reason);
			
		TextView dateTextView = (TextView) arg1.findViewById(R.id.dateTextView);
		dateTextView.setText(redPurse.addtime);
		TextView validTextView = (TextView) arg1
				.findViewById(R.id.validTextView);
		validTextView.setText("有效期 : " + redPurse.endtime);
		
		return arg1;
	}

}
